from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-05 14:05:25.348225
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 05, Sep, 2022
Time: 14:05:31
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3267
Nobs: 770.000 HQIC: -50.6608
Log likelihood: 9841.63 FPE: 8.08222e-23
AIC: -50.8698 Det(Omega_mle): 7.19607e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299480 0.054466 5.498 0.000
L1.Burgenland 0.106510 0.036261 2.937 0.003
L1.Kärnten -0.106922 0.019269 -5.549 0.000
L1.Niederösterreich 0.204930 0.075841 2.702 0.007
L1.Oberösterreich 0.114691 0.073441 1.562 0.118
L1.Salzburg 0.253124 0.038807 6.523 0.000
L1.Steiermark 0.036065 0.050592 0.713 0.476
L1.Tirol 0.107008 0.040989 2.611 0.009
L1.Vorarlberg -0.060764 0.035247 -1.724 0.085
L1.Wien 0.050663 0.065244 0.777 0.437
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059675 0.113136 0.527 0.598
L1.Burgenland -0.034397 0.075321 -0.457 0.648
L1.Kärnten 0.047373 0.040025 1.184 0.237
L1.Niederösterreich -0.176672 0.157535 -1.121 0.262
L1.Oberösterreich 0.395096 0.152549 2.590 0.010
L1.Salzburg 0.290074 0.080610 3.599 0.000
L1.Steiermark 0.106048 0.105089 1.009 0.313
L1.Tirol 0.314510 0.085142 3.694 0.000
L1.Vorarlberg 0.027217 0.073214 0.372 0.710
L1.Wien -0.021729 0.135523 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191918 0.027987 6.857 0.000
L1.Burgenland 0.089440 0.018632 4.800 0.000
L1.Kärnten -0.008592 0.009901 -0.868 0.386
L1.Niederösterreich 0.261020 0.038970 6.698 0.000
L1.Oberösterreich 0.134085 0.037737 3.553 0.000
L1.Salzburg 0.045938 0.019941 2.304 0.021
L1.Steiermark 0.018090 0.025996 0.696 0.487
L1.Tirol 0.093269 0.021062 4.428 0.000
L1.Vorarlberg 0.058222 0.018111 3.215 0.001
L1.Wien 0.117749 0.033525 3.512 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108276 0.028465 3.804 0.000
L1.Burgenland 0.047405 0.018951 2.502 0.012
L1.Kärnten -0.014896 0.010070 -1.479 0.139
L1.Niederösterreich 0.191380 0.039635 4.829 0.000
L1.Oberösterreich 0.290060 0.038381 7.557 0.000
L1.Salzburg 0.111522 0.020281 5.499 0.000
L1.Steiermark 0.102894 0.026440 3.892 0.000
L1.Tirol 0.110589 0.021422 5.163 0.000
L1.Vorarlberg 0.069738 0.018420 3.786 0.000
L1.Wien -0.017681 0.034097 -0.519 0.604
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130922 0.051685 2.533 0.011
L1.Burgenland -0.051005 0.034410 -1.482 0.138
L1.Kärnten -0.040293 0.018285 -2.204 0.028
L1.Niederösterreich 0.170174 0.071969 2.365 0.018
L1.Oberösterreich 0.139663 0.069691 2.004 0.045
L1.Salzburg 0.287670 0.036826 7.812 0.000
L1.Steiermark 0.033447 0.048009 0.697 0.486
L1.Tirol 0.161757 0.038897 4.159 0.000
L1.Vorarlberg 0.100673 0.033447 3.010 0.003
L1.Wien 0.068896 0.061913 1.113 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056025 0.041138 1.362 0.173
L1.Burgenland 0.040329 0.027388 1.473 0.141
L1.Kärnten 0.050473 0.014554 3.468 0.001
L1.Niederösterreich 0.220513 0.057282 3.850 0.000
L1.Oberösterreich 0.282693 0.055469 5.096 0.000
L1.Salzburg 0.045372 0.029311 1.548 0.122
L1.Steiermark -0.000607 0.038212 -0.016 0.987
L1.Tirol 0.147980 0.030959 4.780 0.000
L1.Vorarlberg 0.072929 0.026622 2.739 0.006
L1.Wien 0.085087 0.049278 1.727 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179818 0.049262 3.650 0.000
L1.Burgenland -0.005931 0.032796 -0.181 0.856
L1.Kärnten -0.061433 0.017428 -3.525 0.000
L1.Niederösterreich -0.083999 0.068594 -1.225 0.221
L1.Oberösterreich 0.195984 0.066423 2.951 0.003
L1.Salzburg 0.056517 0.035099 1.610 0.107
L1.Steiermark 0.231151 0.045758 5.052 0.000
L1.Tirol 0.494006 0.037073 13.325 0.000
L1.Vorarlberg 0.047972 0.031879 1.505 0.132
L1.Wien -0.051923 0.059009 -0.880 0.379
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166143 0.056557 2.938 0.003
L1.Burgenland -0.010271 0.037653 -0.273 0.785
L1.Kärnten 0.067095 0.020008 3.353 0.001
L1.Niederösterreich 0.206109 0.078752 2.617 0.009
L1.Oberösterreich -0.070914 0.076260 -0.930 0.352
L1.Salzburg 0.211472 0.040297 5.248 0.000
L1.Steiermark 0.115662 0.052534 2.202 0.028
L1.Tirol 0.072037 0.042563 1.692 0.091
L1.Vorarlberg 0.121604 0.036600 3.323 0.001
L1.Wien 0.122643 0.067748 1.810 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357638 0.032705 10.935 0.000
L1.Burgenland 0.005534 0.021774 0.254 0.799
L1.Kärnten -0.023378 0.011570 -2.020 0.043
L1.Niederösterreich 0.214238 0.045540 4.704 0.000
L1.Oberösterreich 0.188203 0.044099 4.268 0.000
L1.Salzburg 0.046039 0.023303 1.976 0.048
L1.Steiermark -0.015576 0.030379 -0.513 0.608
L1.Tirol 0.106581 0.024613 4.330 0.000
L1.Vorarlberg 0.073558 0.021165 3.476 0.001
L1.Wien 0.048548 0.039177 1.239 0.215
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040025 0.148247 0.192276 0.157231 0.124508 0.112977 0.065968 0.222252
Kärnten 0.040025 1.000000 -0.004071 0.132526 0.041593 0.095747 0.430765 -0.052289 0.100375
Niederösterreich 0.148247 -0.004071 1.000000 0.337805 0.151473 0.297944 0.107318 0.183280 0.322990
Oberösterreich 0.192276 0.132526 0.337805 1.000000 0.228638 0.330555 0.172819 0.167827 0.264979
Salzburg 0.157231 0.041593 0.151473 0.228638 1.000000 0.147742 0.122380 0.147329 0.133501
Steiermark 0.124508 0.095747 0.297944 0.330555 0.147742 1.000000 0.151301 0.138581 0.079462
Tirol 0.112977 0.430765 0.107318 0.172819 0.122380 0.151301 1.000000 0.115097 0.153153
Vorarlberg 0.065968 -0.052289 0.183280 0.167827 0.147329 0.138581 0.115097 1.000000 0.006799
Wien 0.222252 0.100375 0.322990 0.264979 0.133501 0.079462 0.153153 0.006799 1.000000